package com.tanhua;

import org.junit.Test;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

public class HuanXinDemo {

    @Test  //使用环信的必要要求：先获取token(接下来的任何一个动作都会传递token)
    public void test1(){
        //创建一个客户端和环信交互
        RestTemplate restTemplate=new RestTemplate();
        // 指定地址
        String url="http://a1.easemob.com/1172210114153525/demo/token";
        // 指定request参数
        Map map=new HashMap<>();
        map.put("grant_type","client_credentials");
        map.put("client_id","YXA6fnvNvj0mTWWxSR9wD32vwA");
        map.put("client_secret","YXA6iWKFDPnv_8LLPS85xaR-WfHZ2a8");
        // 发送post请求获取respose响应内容
        ResponseEntity<Map> mapResponseEntity = restTemplate.postForEntity(url, map, Map.class);
        Map body = mapResponseEntity.getBody();
        String access_token =(String)body.get("access_token");
        System.out.println(access_token);
    }
}
